#include <iostream>
#include <ctype.h>
#include <stdlib.h>
#pragma warning
using namespace std;
void InputMatrix(int d1, int d2, int* matrix)
{
   cout << "Please input the elements of the matrix:" << endl;
   for (int i = 0; i < d1 * d2; i++)
   {
       cin >> matrix[i];
   }
   cout << "---------------------------------------------------------" << endl;
}
void OutputMatrix(int d1, int d2, int* matrix)
{
   cout << "The original matrix you input is:" << endl;
   for (int i = 0; i < d1 * d2; i++)
   {
       cout << matrix[i] << "    ";
       if ((i + 1) % d1 == 0)
           cout << endl;
   }
   cout << "---------------------------------------------------------" << endl;
}
void TransposeMatrix(int d1, int d2, int* matrix) 
{
   int i, j;
   cout << "The transposed matrix is:" << endl;
   for (i = 1; i <= d1; i++)
   {
       for (j = 1; j <= d2; j++)
       {
           cout << matrix[(j - 1) * d1 + i - 1]<<"    ";
       }
       cout << endl;
   }
   cout << "---------------------------------------------------------" << endl;
}
void main() 
{
   int i, d1 = 0, d2 = 0, * matrix = NULL;
   char flag = 'y';
   while (tolower(flag) == 'y')
   {
       matrix = new int[100];
       cout << "Please input two dimensions of the matrix: ";
       cin >> d1 >> d2;
       InputMatrix(d1, d2, matrix);
       OutputMatrix(d1, d2, matrix);
       TransposeMatrix(d1, d2, matrix);
       cout << "Do you want to continue to transpose the matrix?(Y/N)";
       cin >> flag;
       delete[]matrix;
   }
}